#!/usr/bin/python
# -*- coding: UTF-8 -*-

#
# the data element of a map
# @author Lee
#
class _MapElement:
    _key : None
    _value : None

    def __init__(self, key):
        self._key = key
        self._value = None

    def GetKey(self):
        return self._key

    def SetValue(self, value):
        self._value = value

    def GetValue(self):
        return self._value
        
#
# the map data structure
#     this map is suitable for adding and finding
#     it is run slowly when deleting
# @author Lee
#
class Class:
    _dataList = None
    _dataDict = None

    def __init__(self):
        self._dataList = []
        self._dataDict = {}

    def ExistData(self, key):
        if None == self._dataDict or None == self._dataList:
            return False
        
        if key not in self._dataDict:
            return False

        return True

    def SetData(self, key, value):
        if None == self._dataDict or None == self._dataList:
            return

        if key in self._dataDict:
            mapElement = self._dataDict[key]
            mapElement.SetValue(value)
        else:
            mapElement = _MapElement(key)
            mapElement.SetValue(value)
            self._dataList.append(mapElement)
            self._dataDict[key] = mapElement
        
    def FindData(self, key):
        if None == self._dataDict:
            return None

        if key not in self._dataDict:
            return None
        
        mapElement = self._dataDict[key]
        elementValue = mapElement.GetValue()
        return elementValue
    
    def GetCount(self):
        if None == self._dataList:
            return 0
        
        dataCount = len(self._dataList)
        return dataCount

    def GetData(self, index):
        if None == self._dataList:
            return 0
        
        dataCount = len(self._dataList)
        if index < 0 or index >= dataCount:
            return 0
        
        mapElement = self._dataList[index]
        elementValue = mapElement.GetValue()
        return elementValue
    
